package com.jsoft.model;

import com.jsoft.dto.OrderDto;
import com.jsoft.model.core.BaseDao;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * Date: 05.09.13
 * Time: 9:21
 */

@Entity
@Table(name = "orders")
public class OrderDao extends BaseDao {
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "order_id")
    private List<OrderItemDao> orderItemList;
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "order_dis_marg",
            joinColumns = @JoinColumn(name = "order_id"),
            inverseJoinColumns = @JoinColumn(name = "dismarg_id")
    )
    private List<DiscountMarginDao> disMargList;
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "order_service",
            joinColumns = @JoinColumn(name = "order_id"),
            inverseJoinColumns = @JoinColumn(name = "service_id")
    )
    private List<ServiceDao> serviceList;
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "place_id")
    private PlaceDao place;
    @Column(name = "count_clients")
    private Integer clientCount;
    @Column(name = "total_amount")
    private BigDecimal totalAmount;
    @Column(name = "discount_amount")
    private BigDecimal discountAmount;
    @Column(name = "margin_amount")
    private BigDecimal marginAmount;
    @Column(name = "amount")
    private BigDecimal amount;
    @Column(name = "status")
    private Integer status;

    public List<OrderItemDao> getOrderItemList() {
        return orderItemList;
    }

    public void setOrderItemList(List<OrderItemDao> orderItemList) {
        this.orderItemList = orderItemList;
    }

    public List<DiscountMarginDao> getDisMargList() {
        return disMargList;
    }

    public void setDisMargList(List<DiscountMarginDao> disMargList) {
        this.disMargList = disMargList;
    }

    public List<ServiceDao> getServiceList() {
        return serviceList;
    }

    public void setServiceList(List<ServiceDao> serviceList) {
        this.serviceList = serviceList;
    }

    public PlaceDao getPlace() {
        return place;
    }

    public void setPlace(PlaceDao place) {
        this.place = place;
    }

    public Integer getClientCount() {
        return clientCount;
    }

    public void setClientCount(Integer clientCount) {
        this.clientCount = clientCount;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getDiscountAmount() {
        return discountAmount;
    }

    public void setDiscountAmount(BigDecimal discountAmount) {
        this.discountAmount = discountAmount;
    }

    public BigDecimal getMarginAmount() {
        return marginAmount;
    }

    public void setMarginAmount(BigDecimal marginAmount) {
        this.marginAmount = marginAmount;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public OrderDto wrapOrderDto() {
        OrderDto dto = new OrderDto();
        dto.setId(this.getObjectId());
        dto.setClientCount(this.getClientCount());
        return dto;
    }

    public OrderDao wrapOrderDao(OrderDto dto) {
        OrderDao dao = new OrderDao();
        dao.setClientCount(dto.getClientCount());
        return dao;
    }
}
